﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<CRM.Models.TrainingsSchedules>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<int>" %>

<%
    var coursesCol = new CRM.Database.Model.TrainingsCoursesCollection();
    var placesCol = new CRM.Database.Model.TrainingsPlacesCollection();
    var schedulesCol = new CRM.Database.Model.TrainingsSchedulesCollection();
%>

<%Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsSchedule";
                                        settings.KeyFieldName = "IdTrainingsSchedule";
                                        settings.CallbackRouteValues = new { Controller = "TC", Action = "TraningsSchedulesRequestPartial", customerId = Model};
                                        settings.SettingsPager.PageSize = 20;
                                        //settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = " ";
                                            column.FieldName = "IdTrainingsSchedule";
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
                                            String urlFormatString = Url.Action("TrainingsPlannedRequestCreate", "TC", new RouteValueDictionary(new { scheduleId = "{0}", customerId = Model }));
                                            properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                            properties.TextField = "LinkText";
                                        });
                                        
                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = "Дата";
                                            column.FieldName = "PlannedDate";
                                            column.PropertiesEdit.DisplayFormatString = "d";
                                            column.Settings.FilterMode = ColumnFilterMode.Value;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.BeginsWith;
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCource";
                                            column.Caption = "Рубрика";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                comboBoxProperties.DataSource = coursesCol.TrainingsCoursesActiveList;
                                                //comboBoxProperties.DataSource = DB.TrainingsCourses;
                                                comboBoxProperties.TextField = "RubricName";
                                                comboBoxProperties.ValueField = "IdTrainingsCourse";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCource";
                                            column.Caption = "Курс";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                comboBoxProperties.DataSource = coursesCol.TrainingsCoursesActiveList;
                                                //comboBoxProperties.DataSource = DB.TrainingsCourses;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdTrainingsCourse";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsPlace";
                                            column.Caption = "Город";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                comboBoxProperties.DataSource = placesCol.TrainingsPlacesActiveList;
                                                //comboBoxProperties.DataSource = DB.TrainingsPlaces;
                                                comboBoxProperties.TextField = "TrainingsCityName";
                                                comboBoxProperties.ValueField = "IdTrainingsPlace";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                    }).Bind(schedulesCol.GetSchedulesListByCourseType(1, true).OrderByDescending(p => p.PlannedDate)).GetHtml();
                                    //}).Bind(DB.GetTrainingsSchedulesByCourseType(1).OrderByDescending(p => p.PlannedDate)).GetHtml();
%>